layui.use(['form','table','laypage'], function(){
  var table = layui.table;
  var form = layui.form;
  var curr_page = 0;
	/*初始化表格*/
	function tableInit(where = {})
	{  
	  table.render({
		elem: '#dataTables-example'
		,url:'/shop/activity/headactivity.html'
        ,where:where
		,method:'POST'
		,parseData: function(res){ //res 即为原始返回的数据
			//封装返回数据
			console.log(res);
			var urls = '';
			curr_page = res.current_page;
			
			for (i in res.data) {
					urls = '/shop/activity/headainfo/id/'+res.data[i]['activity_id']+'.html';
					res.data[i]['reason'] = "<button class='layui-btn' onclick=\"xadmin.open('活动详情','"+urls+"',800,500)\">详情</button>";
			}
			return {
			  "code": 10001,
			  "msg": '',
			  "count": res.total,
			  "data": res.data
			};
		}
		,cols: [[
		  {field:'activity_id', title: '序号'}
		  ,{field:'time', title: '活动时间'} 
		  ,{field:'shop_id', title: '门店'}
		  ,{field:'act_type', title: '活动类型'}
		  ,{field:'act_name', title: '活动名称'}
          ,{field:'remarks', title: '活动规则'}
		  ,{field:'reason', title: '操作'}
		]]
		,page: {
		  layout: ['prev', 'page', 'next', 'skip', 'count']
		  ,curr:curr_page
		}
		,response: {
			statusCode: 10001
		}
	  });
	};
	tableInit();
    //监听提交
	form.on('submit(sreach)',
	function(data) {
		tableInit(data.field);
		return false;
	});
});

